package com.example.administrator.asdasd;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class Fragment_sc extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shouchang, container, false);
        SQLdm s = new SQLdm();
        SQLiteDatabase db = s.openDatabase(getActivity().getApplication());
        Cursor c = db.rawQuery("select * from cztb where czs=?", new String[]{"1"});
        List<ItemBean> itemBeanList = new ArrayList<>();
        if (c != null) {
            while (c.moveToNext()) {
                itemBeanList.add(new ItemBean(
                        "车主 ：" + c.getString(c.getColumnIndex("name")),
                        "联系方式:" + c.getString(c.getColumnIndex("num")),
                        "载重 ：" + c.getString(c.getColumnIndex("max"))+"吨",
                        "tell:"+c.getString(c.getColumnIndex("num"))
                ));
            }
        }
        c.close();
        Cursor c1 = db.rawQuery("select * from hztb where hzs=?", new String[]{"1"});
        if (c1 != null) {
            while (c1.moveToNext()) {
                itemBeanList.add(new ItemBean(
                        "货主 ：" + c1.getString(c1.getColumnIndex("name")),
                        "载重 ：" + c1.getString(c1.getColumnIndex("max"))+"吨",
                        c1.getString(c1.getColumnIndex("weizhi")) + "  -- " + c1.getString(c1.getColumnIndex("aim")),
                        "tell:"+c1.getString(c1.getColumnIndex("num"))
                ));
            }
        }
        c1.close();
        db.close();
        ListView listView = (ListView) view.findViewById(R.id.listView2);
        listView.setAdapter(new new_MyAdapter(MainActivity.Mythis, itemBeanList));
       return view;
    }
}
